package observer;

import java.awt.List;
import java.util.LinkedList;
import java.util.Random;

import javax.swing.text.html.HTMLDocument.Iterator;

public class Senzor implements Subject{
	private LinkedList<Observer> obs = new LinkedList<Observer> ();
	private int valCurenta = 0;
	
		public void addObserver(Observer o){
			obs.add(o);
		}
		
	
	//sterge un Observer
	public void removeObserver(Observer o){
			obs.remove(o);
		}

	
	//Notifica Observerii
	public void notifyObserver(){
		Iterator i = (Iterator) obs.iterator();
		while ( i.hasNext()){
			Observer o = (Observer) i.next();
			o.upDate(this);
		}
	}
	
	//Genereaza un nr aleator
	public void generare(){
		Random serieRandom = new Random();
		valCurenta = serieRandom.nextInt(80);
		notifyObserver();
	}
	
	
	//Returneaza valoarea curenta
	public int getVal() {
		
		return valCurenta;
	}
	public void addObserver(java.util.Observer o) {
		// TODO Auto-generated method stub
		
	}
	public void removeObserver(java.util.Observer o) {
		// TODO Auto-generated method stub
		
	}

}
